<template>
  <div class="tlogin">
    <h1>教师登录页面</h1>
    <img alt="Vue logo" src="../assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js App"/>
    <input type="text" v-model="loginForm.username" placeholder="用户名"/>
    <input type="text" v-model="loginForm.password" placeholder="密码"/>
    <button @click="login">登录</button>
 </div>
</template>

<script>
<<<<<<< HEAD
// @ is an alias to /src
=======
<<<<<<< HEAD
import { mapMutations } from 'vuex';
=======
// @ is an alias to /src。。
>>>>>>> 8ca49b8cfe660b8c8c37ad39782b9916923bd370
import HelloWorld from '@/components/HelloWorld.vue'

>>>>>>> 0b8d5803bbd660b2992441004c620fade61b6e88
export default {
 data () {
 return {
 loginForm: {
 username: '',
 password: ''
 }
 };
 },
 
 methods: {
 ...mapMutations(['changeLogin']),
 login () {
 let _this = this;
 if (this.loginForm.username === '' || this.loginForm.password === '') {
 alert('账号或密码不能为空');
 } else {
 this.axios({
 method: 'post',
 url: '/user/login',
 data: _this.loginForm
 }).then(res => {
 console.log(res.data);
 _this.userToken = 'Bearer ' + res.data.data.body.token;
 // 将用户token保存到vuex中
 _this.changeLogin({ Authorization: _this.userToken });
 _this.$router.push('/home');
 alert('登陆成功');
 }).catch(error => {
 alert('账号或密码错误');
 console.log(error);
 });
 }
 }
 }
};
</script>